
import { _ } from '../../libs/underscore/underscore.modified'
var app = getApp()

var temp = {
  //计算位置
  format: function (data) {
    let list = _.map(data, function (item) {
      let distance = app.getDistance(item.Lat, item.Lng);
      item.distance = distance;
      return item;
    });
    return list;
  },
  //日期格式化函数
  crtTimeFtt: function (value, fmt) {
    var date = new Date(value);
    var o = {
      "M+": date.getMonth() + 1,                 //月份   
      "d+": date.getDate(),                    //日   
      "h+": date.getHours(),                   //小时   
      "m+": date.getMinutes(),                 //分   
      "s+": date.getSeconds(),                 //秒   
      "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
      "S": date.getMilliseconds()             //毫秒   
    };
    if (/(y+)/.test(fmt))
      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
      if (new RegExp("(" + k + ")").test(fmt))
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
  },
  Sui: function () {
    var r = Math.floor(Math.random() * 10);
    if (r > 2) {
      return this.Sui();
    } else {
      return r;
    }
  },
  // 计算时间
  secondToMin: function (time) {
    let m = Math.floor(time / 60);
    m = m < 0 ? 0 : m;
    let M = m < 10 ? "0" + m : m;
    let s = time % 60;
    s = s < 0 ? 0 : s;
    let S = s < 10 ? "0" + s : s;
    var min = M + ":" + S;
    return min.split('.')[0];
  },
  //根基下标移除数据对象
  baoremove: function (List, dx) {
    if (isNaN(dx) || dx > this.length) { return false; }
    List.splice(dx, 1);
  },

}
export default temp